﻿using System;
using System.Collections.Generic;
using System.Linq;

class ScoreBoard
{
    public const int TOP_RESULTS_CAPACITY = 5;
    private List<Result> topResults;

    public ScoreBoard()
    {
        topResults = new List<Result>();
        topResults.Capacity = TOP_RESULTS_CAPACITY;
    }

    public void Print()
    {
        if (topResults.Count == 0)
        {
            UserIntefrace.PrintScoreBoardEmptyMessage();
        }
        else
        {
            for (int index = 0; index < topResults.Count; index++)
            {
                Console.WriteLine("{0}. {1} --> {2} moves", index + 1,
                    topResults[index].PlayerName, topResults[index].MovesCount);
            }
        }
    }

    public bool IsTopScore(int result)
    {
        if (topResults.Count < TOP_RESULTS_CAPACITY)
        {
            return true;
        }
        if (result < topResults.Max().MovesCount)
        {
            return true;
        }
        return false;
    }

    public void AddResultInScoreboard(int movesCount, string playerName)
    {
        Result result = new Result(movesCount, playerName);
        if (topResults.Count == topResults.Capacity)
        {
            topResults[topResults.Count - 1] = result;
        }
        else
        {
            topResults.Add(result);
        }
        topResults.Sort();
    }
}
